34d184579e52793b4e966fec4851cba7ee631950,src/edu/stanford/nlp/util/concurrent/ConcurrentHashIndex.java,ConcurrentHashIndex,indexOf,#E#boolean#,70

Before Change



  @Override
  public int indexOf(E o, boolean add) {
    Integer atomic = item2Index.get(o);
    if (atomic == null) {
      if (add) {
        final int newIndex = indexCounter.getAndIncrement();
        atomic = item2Index.putIfAbsent(o, newIndex);
        if (atomic == null) {
          index2Item.put(newIndex, o);
          return newIndex;
        } else {
          return item2Index.get(o);
        }
      } else {
        return UNKNOWN_ID;
      }
    } else {
      return atomic;
    }
  }

After Change


      // TODO(spenceg) The Index interface contract states that indices must be
      // non-negative and continuous. We tried to satisfy this requirement without
      // a lock (e.g., by using AtomicInteger) but couldn't make it work.
      synchronized(this) {
        if ( ! item2Index.containsKey(o)) {
          int newIndex = index2Item.size();
          item2Index.put(o, newIndex);
          index2Item.put(newIndex, o);
        }
      }
      return item2Index.get(o);

    } else {
      return indexOf(o);
    }
  }